﻿using FCTIP20.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace FCTIP20.View
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        public MainWindow(string msg, string sn)
        {
            InitializeComponent();
            tbDevSN.Text = $"设备序列号: {sn}";
            var licenseInfo = msg.Split(',').ToList();
            tbLicenseInfo.Text = $"软件有效期至: {licenseInfo[0]}, 剩余: {licenseInfo[1]}天";
            var model = new MainWindowModel();
            this.DataContext = model;
            Task.Run(() =>
            {
                while (true)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        tbSysTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    });
                    Thread.Sleep(1000);
                }
            });

        }
        private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
                this.DragMove();
        }

        private void btExit_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
            Environment.Exit(0);
        }

        private void btnToggleWin_Click(object sender, RoutedEventArgs e)
        {
            if (WindowState == WindowState.Normal)
            {
                WindowState = WindowState.Maximized;
            }
            else
            {
                WindowState = WindowState.Normal;
            }
        }
    }
}
